package player.ui.browse;

import java.awt.Graphics;
import java.awt.Point;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;

import net.miginfocom.swing.MigLayout;
import player.Tools;
import player.mplayer.MediaInfo;
import player.ui.playlist.PlayListManage;
import player.ui.playlist.PlayListModel;

public class ImageButton extends JComponent{
	private static final long serialVersionUID = 2594964287838188899L;
	public Icon smallIcon=null;
	public Icon largeIcon=null;
	boolean startDrag=false;   
	Point startMouseLocation=null;   
	static boolean mousePress=false;
	static boolean hasRightClick=false;
	Point startLocation=null;
	ImgButtonItem ImgButtonItem;
	String mediaPath;
	public ImageButton(PlayListManage pm,PlayListModel plm,
			MediaInfo media,int index,String text,Icon smallIcon,File[] imgFile) {
		super();
		ImgButtonItem=new ImgButtonItem(pm,plm,media,index,text,imgFile);
		ImgButtonItem.setLayout(new MigLayout("insets 0 0 0 0","[]","[]"));
		this.smallIcon=smallIcon;
		setLayout(new MigLayout("insets 0 0 0 0","","[][][]"));
		add(ImgButtonItem,"width 0:10240: ,height 0:10240:");
		setBorder(BorderFactory.createEtchedBorder());
		
		JButton label2=Tools.creatButton(text);
		Tools.removeAllMouseListener(label2);
		label2.setDoubleBuffered(true);
		label2.setIcon(smallIcon);
		ImgButtonItem.add(label2,"width 0:: ,height :: ,wrap");
		
		ImgButtonItem.add(Tools.creatTranPanel(),"width 0:10240: ,height 0:10240: ,wrap");
		
		//ImgButtonItem.add(label3,"width 0:2048: ,height :: ");
//		
//		this.addMouseMotionListener(new MouseMotionListener(){
//
//			public void mouseDragged(MouseEvent e) {
//				if(e.getModifiers()==16){
//					if(startDrag){
//						Point nowMouseLocation=MouseInfo.getPointerInfo().getLocation();
//						Point newFrameLocation=new Point();
//						newFrameLocation.x=startLocation.x+nowMouseLocation.x-startMouseLocation.x;
//						newFrameLocation.y=startLocation.y+nowMouseLocation.y-startMouseLocation.y;
//						//ImageButton.setLocation(newFrameLocation);}
//				}
//			}
//
//			public void mouseMoved(MouseEvent e) {
//				
//			}
//			
//		});
//		
//		addMouseListener(new MouseListener(){
//			
//			public void mouseClicked(MouseEvent e) {
//				if(e.getButton()==3){
//					hasRightClick=true;
//				}else{
//					hasRightClick=false;
//				}
//			}
//
//			public void mouseEntered(MouseEvent e) {}
//
//			public void mouseExited(MouseEvent arg0) {}
//
//			public void mousePressed(MouseEvent e) {
//				mousePress=true;
//				startDrag=true;
//				startMouseLocation=MouseInfo.getPointerInfo().getLocation();
//				startLocation=ImageButton.getLocation();
//			}
//
//			public void mouseReleased(MouseEvent arg0) {
//				startDrag=false;
//				mousePress=false;
//			}
//			
//		});
		
	}
	public void paint(Graphics g){
		//paintComponent(g);
		paintComponents(g);
	}
	
	public void repaint(){
		ImgButtonItem.refresh();
	}
	
//	public void update(Graphics g){
//		System.out.println("111update(Graphics g)update(Graphics g)");
//	}
//	
//	
//	public void  update(){
//
//		System.out.println("111updateupdateupdateupdateupdate");
//	}
	
}
